package com.comm.controller;

import com.comm.domain.dto.ExpressCompanyMappingBatchDTO;
import com.comm.entity.ExpressCompanyMapping;
import com.comm.entity.Page;
import com.comm.entity.User;
import com.comm.service.IExpressCompanyMappingService;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 系统平台物流公司关系映射
 */
@Controller
@RequestMapping("/trade/express/mapping")
public class ExpressCompanyMappingController {

    @Resource
    private IExpressCompanyMappingService expressCompanyMappingService;

//    @RequestMapping(value = "/batchAdd", method = RequestMethod.POST)
//    @ResponseBody
//    public Object batchAdd(@RequestBody List<ExpressCompanyMapping> list, String cacheKey) throws Exception {
//        if (CollectionUtils.isEmpty(list)) {
//            throw new RuntimeException("新增的数据数组不能为空");
//        }
//        return expressCompanyMappingService.batchAdd(list);
//    }

    @RequestMapping(value = "/addBatch", method = RequestMethod.POST)
    @ResponseBody
    public Object batchAdd(@RequestBody ExpressCompanyMappingBatchDTO  expressCompanyMappingBatchDTO) throws Exception {
        Assert.notNull(expressCompanyMappingBatchDTO, "新增的数据不能为空");
        Assert.notEmpty(expressCompanyMappingBatchDTO.getList(), "新增的数据不能为空");
        return expressCompanyMappingService.addBatch(expressCompanyMappingBatchDTO.getList());

    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public Object add(ExpressCompanyMapping expressCompanyMapping) throws Exception {
        if (ObjectUtils.isEmpty(expressCompanyMapping)) {
            throw new RuntimeException("新增的数据不能为空");
        }
        expressCompanyMappingService.addExpressCompanyMapping(expressCompanyMapping);
        return 1;
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public Object delete(Long id) throws Exception {
        return expressCompanyMappingService.logicDeleteById(id);
    }

    //
//    @RequestMapping(value = "/batchUpdate", method = RequestMethod.POST)
//    @ResponseBody
//    public Object batchUpdate(List<ExpressCompanyMapping> expressCompanyMappingList) throws Exception {
//        if (CollectionUtils.isEmpty(expressCompanyMappingList)) {
//            throw new RuntimeException("需要更新的的数据数组不能为空");
//        }
//        return expressCompanyMappingService.batchUpdate(expressCompanyMappingList);
//    }
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public Object batchUpdate(ExpressCompanyMapping expressCompanyMapping) throws Exception {
        return expressCompanyMappingService.update(expressCompanyMapping);
    }

    @RequestMapping(value = "/getList", method = RequestMethod.POST)
    @ResponseBody
    public Object delgetListete(ExpressCompanyMapping expressCompanyMapping, Page page) throws Exception {
        if (ObjectUtils.isEmpty(expressCompanyMapping)) {
            throw new RuntimeException("查询参数不能为空");
        }
        return expressCompanyMappingService.getListByExample(expressCompanyMapping, page);

    }

    @RequestMapping(value = "/getMappingMap", method = RequestMethod.POST)
    @ResponseBody
    public Object getMappingMap(String source) throws Exception {
        User user = new User();
        user.setSource(source);
        return expressCompanyMappingService.getExpressMappingMap(user);
    }

}
